package com.lyfei.ydc.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lyfei.ydc.domain.entity.Sku;
import com.lyfei.ydc.domain.entity.Spu;
import com.lyfei.ydc.mapper.SkuMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("skuService")
public class SkuService extends BaseService<SkuMapper, Sku>{
    @Autowired
    private SpuService spuService;
    public List<Sku> getSkuListByIds(List<Long> ids) {
        List<Sku> result = this.list(new QueryWrapper<Sku>().in("id", ids));
        result.forEach(item -> {
            if(item.getImg() == null) {
                Spu spu = spuService.getById(item.getSpuId());
                item.setImg(spu.getImg());
            }
        });

        return result;
    }
}
